<?php
function openDB($path) {
  return sqlite_open($path);
}
function getConfig() {
  return sqlite_fetch_array(sqlite_query($GLOBALS['db'],"SELECT * FROM config"));
}
function getPageById($pageid) {
  return sqlite_fetch_array(sqlite_query($GLOBALS['db'],"SELECT * FROM pages WHERE id = ".$pageid));
}
function getPage($title) {
  return sqlite_fetch_array(sqlite_query($GLOBALS['db'],"SELECT * FROM pages WHERE name LIKE '$title'"));
}
function getIdFromName($name) {
  return sqlite_fetch_single(sqlite_query($GLOBALS['db'],"SELECT id FROM pages WHERE name = '$name'"));
}
function getNameFromId($id) {
  return sqlite_fetch_single(sqlite_query($GLOBALS['db'],"SELECT name FROM pages WHERE id = '$id'"));
}
function exists($table,$column,$value) {
  return sqlite_fetch_single(sqlite_query($GLOBALS['db'],"SELECT $column FROM $table WHERE $column LIKE '$value'"));
}
function hasChildren($title) {
  return sqlite_fetch_all(sqlite_query($GLOBALS['db'],"SELECT parent FROM pages WHERE parent = '$title'"));
}
function getLatest() {
  $latestid['pages'] = sqlite_fetch_single(sqlite_query($GLOBALS['db'],"SELECT id FROM pages ORDER BY id DESC"))+0;
  return $latestid;
}
?>